﻿using MediatR;
using T_settlement.API.Application.Command.PaymentCommand;
using T_settlement.Infrastructure.Interfacec;

namespace T_settlement.API.Application.CommandHandlers.PaymentCommandHandlers
{
    public class PDelPaymentCommandHandlers:IRequestHandler<PDelPaymentCommand,int>
    {
        private readonly IPaymentRepository paymentRepository;

        public PDelPaymentCommandHandlers(IPaymentRepository paymentRepository)
        {
            this.paymentRepository = paymentRepository;
        }

        public async Task<int> Handle(PDelPaymentCommand request, CancellationToken cancellationToken)
        {
            var Id = request.PaymentId.Split(',').Select(x => Convert.ToInt32(x));
            var list = await paymentRepository.GetAsync(x => Id.Contains(x.PaymentId));
            foreach (var item in list)
            {
                item.IsDel = true;
            }
            return await paymentRepository.UpdateAsyncRange(list);
        }
    }
}
